/**
 * @(#)Proxy.java, Sep 19, 2012. 
 * 
 * Copyright 2012 Yodao, Inc. All rights reserved.
 * YODAO PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.buaaer.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 *
 * @author wangheng
 *
 */
public class TestProxy {

    public static void main(String[] args) {
        Hello hello = new HelloImpl();
        HelloHandler handler = new HelloHandler(hello);
        
        Hello proxy = (Hello) Proxy.newProxyInstance(
                hello.getClass().getClassLoader(), hello.getClass().getInterfaces(),
                handler);
        
        System.out.println(proxy.concat("s1", "s2"));
    }
}


class HelloHandler implements InvocationHandler {
    
    Object obj;
    
    public HelloHandler(Object obj) {
        this.obj = obj;
    }

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        
        return method.invoke(obj, args);
    }
    
}

interface Hello {
    
    public String concat(String s1, String s2);
}

class HelloImpl implements Hello {

    public String concat(String s1, String s2) {
        return s1 + s2;
    }
    
}
